package com.vmix.vmixmobiledemo;

import com.vmix.android.vmixsdk.valueobject.VmixCollections;
import com.vmix.android.vmixsdk.valueobject.VmixVideos;

import android.content.Context;
import android.view.LayoutInflater;
import android.app.Activity;
import android.widget.BaseAdapter;
import android.widget.TextView;

import android.view.View;
import android.view.ViewGroup;


public class VmixCollectionListAdapter extends BaseAdapter {
	
	private Activity activity;
	private String[] data;
	private static LayoutInflater inflater = null;
	
	private VmixCollections collections;
	
	public VmixCollectionListAdapter(Activity a, String[] d) {
		activity = a;
		data = d;
		inflater = (LayoutInflater) activity
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

	}
	
	/**
	 * 
	 * @param a
	 * @param collections
	 */
	public VmixCollectionListAdapter(Activity a, VmixCollections collections) {
		this.activity = a;
		this.collections = collections;
		
		inflater = (LayoutInflater) activity
				.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}

	/**
	 * return the size of the dataset
	 */
	public int getCount() {
		return this.collections.size();
	}

	/**
	 * return the item in the dataset based on the position specified
	 * 
	 */
    public Object getItem(int position) {
    	
    	//return this.collections.
        return this.collections.get( position );
    }

    /**
     * should be the same, but may not be ..
     */
    public long getItemId(int position) {
        return position;
    }
	
    public static class ViewHolder{
    	public TextView text;
    }

    public View getView(int position, View convertView, ViewGroup parent) {
    	View vi=convertView;
    	ViewHolder holder;
		if(convertView==null){
			vi = inflater.inflate(R.layout.collection_cell, null);
			holder=new ViewHolder();
			holder.text=(TextView)vi.findViewById(R.id.text);;
			vi.setTag(holder);
		}
		else {
			holder=(ViewHolder)vi.getTag();
		}
		
		String collectionName = this.collections.get( position ).getName();
		
		// holder.text.setText("item "+position);
		holder.text.setText( collectionName );
		
        return vi;
    }
}
